package mest.service.Modeling.Impl;

import com.alibaba.fastjson.JSON;
import mest.VO.hank.model.save_fileModel;
import mest.VO.hws.save_fileVO;
import mest.dao.Modeling.IsaveFileDao;
import mest.entity.provider_type;
import mest.entity.save_file;
import mest.service.Modeling.IsaveFileService;
import mest.util.ResultObj;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @auther Machenike
 * @create 2019-11-16 1:53
 */
@Service
public class saveFileServiceImpl implements IsaveFileService {

    @Resource
    private IsaveFileDao isfd;

    @Override
    public ResultObj insertsaveFile(save_file sf,String theirDb) {

        try {
            int i = isfd.insertsaveFile(sf,theirDb);
            if (i > 0) {
                return  ResultObj.createSuccessMsg(ResultObj.INSERT_SUCCESS);
            }
        } catch (Exception e) {
            e.printStackTrace();
            if (e.getClass().getName().equals("org.springframework.dao.DuplicateKeyException")) {
                return ResultObj.createErrorMsg("编码重复");
            }
            return ResultObj.createErrorMsg(ResultObj.ERROR);
        }
        return ResultObj.createErrorMsg(ResultObj.ERROR);
    }



    @Override
    public int selectCount(String theirDb) {
        return isfd.selectCount(theirDb);
    }

    @Override
    public List<save_fileVO> findSaveFilePage(int index, int pageSize, String theirDb) {
        return isfd.findSaveFilePage((index-1)*pageSize,pageSize,theirDb );
    }

    @Override
    public int delModel(Integer id,String theirDb) {
        return isfd.delModel(id,theirDb);
    }

    @Override
    public List<save_fileModel> queryAll(Integer index, Integer pageSize, String record,String theirDb) {
        return isfd.queryAllModel((index-1)*pageSize,pageSize, record,theirDb);
    }

    @Override
    public int findCount(String record,String theirDb) {
        return isfd.findCount(record,theirDb);
    }

    @Override
    public int updateByOne(save_file record,String theirDb) {
        return isfd.updateByPrimaryKeySelective(record,theirDb);
    }

    @Override
    public String selectByid(Map<String, Object> map) {
        /* selectById  selectAll  */
        System.out.println("进入查询");
        Map<Object,Object> returnmap = new HashMap<Object,Object>();
        try {
            returnmap.put("code",0);
            returnmap.put("msg","查询成功");
            returnmap.put("count",1);
            returnmap.put("data",isfd.selectByid(map));
        }catch (Exception e){
            System.out.println(e.toString());
            returnmap.put("code",1);
            returnmap.put("msg","查询失败");
            returnmap.put("errmsg",e.toString());
        }
        return JSON.toJSONString(returnmap);
    }


}
